<?php

namespace App\Http\Controllers\Api\V1;

use Zhuzhichao\BankCardInfo\BankCard;

class BanksController extends Controller
{
	
	public function index()
	{
		$list = BankCard::getBankList();
		return response()->json(['list' => $list]);
	}

	public function info()
	{
		$result = file_get_contents("https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo=".request()->bank_card."&cardBinCheck=true");
        $result = json_decode($result);
        if (!$result->validated) {
        	fail('卡号有误');
        }else{
        	$list =  array_keys(BankCard::getBankList());

        	if(!in_array($result->bank,$list)){
        		fail('暂不支持该银行');
        	}
        }	

		$info = BankCard::info(request()->bank_card);
		return response()->json(['info' => $info]);
	}
}
